package cubelabs.nexus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cubelabs.nexus.entity.Institute;
import cubelabs.nexus.entity.User;
import cubelabs.nexus.service.InstituteService;
import cubelabs.nexus.service.NexusService;

import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HomeController {

	@Autowired
	private InstituteService service;
	@Autowired
	private NexusService userService;

	@RequestMapping(method = RequestMethod.POST, value = "/institutes")
	public HttpStatus createInstitute(@RequestBody Institute i) {
		return service.createInstitute(i);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/institutes/{id}")
	public @ResponseBody
	Institute fetchInstitute(@PathVariable("id") long insId) {
		return service.fetchInstitute(insId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/users/{id}")
	public @ResponseBody
	User fetchUser(@PathVariable("id") long id) {
		User user = new User();
		return user;
	}

	@RequestMapping(method = RequestMethod.POST, value = "/users")
	public @ResponseBody
	HttpStatus postUser(@RequestBody User user) {
		userService.registerUser(user);
		return HttpStatus.OK;
	}
}
